package com.ymatou.iapi.fundstrategy.testcase;

import java.util.List;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.fundstrategy.parameter.FundDimension;
import com.ymatou.iapi.fundstrategy.parameter.FundDimensionCreateBean;
import com.ymatou.iapi.fundstrategy.service.FundDimensionCreateCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.common.entitie.ShangouSellerOrdersByProduct;
import com.ymttest.database.model.YmtFundDimension;
import com.ymttest.database.model.YmtProductsI;
import com.ymttest.database.sqlwapper.YmtFundDimensionWapper;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
/**
*创建资金维度信息接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_FundDimensionCreate{
	private static FundDimensionCreateBean funddimensioncreateBean;
	private static FundDimensionCreateCall funddimensioncreateCall;
	private static FundDimension fundDimension;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("创建资金维度信息接口");
	}

	@Before
	public void caseUp() {
		funddimensioncreateBean=new FundDimensionCreateBean();
		funddimensioncreateCall=new FundDimensionCreateCall();
		fundDimension=new FundDimension();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(funddimensioncreateCall.getOpurl());
	}



	
	public static void  fundDgetreturnerrcode(String ecode,String eMsg) throws Exception {
    try {
    	
		//获取返回报文的数据
		String dataStr = funddimensioncreateCall.getReturnData();
		//返回报文断言			
		String dimensionId =  new JSONObject(dataStr).getString("DimensionId");
		Logger.verifyIsNull(dimensionId, "DimensionId为空");
		String errCode =  new JSONObject(dataStr).getString("ErrCode");
		Logger.verifyIsContains(ecode, errCode, "ErrCode");
		String errMsg =  new JSONObject(dataStr).getString("ErrMsg");
		Logger.verifyIsContains(eMsg, errMsg, eMsg);
		String body =  new JSONObject(dataStr).getString("Body");
		Logger.verifyIsNull(body, "Body为空");
		String requestUrl =  new JSONObject(dataStr).getString("RequestUrl");
		Logger.verifyIsNull(requestUrl, "RequestUrl为空");
		String Success =  new JSONObject(dataStr).getString("Success");
		Logger.verifyIsContains(false, Success, "\"Success\":false");
    	    	    	
    }catch (Exception e) {  
        e.printStackTrace();
    }  

}
			
	
	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_FundDimensionCreate_001() {
		Logger.start(true,"创建资金维度信息");
		try {
			//TODO 补全case代码
			int num1 = (int)(Math.random()*10000);
			String strategyDimensionName1="商品类目" + num1;
			
			//资金维度 （接口第一层）
			funddimensioncreateBean.setFundDimension(fundDimension);
				//接口第二层
				fundDimension.setStrategyDimensionName(strategyDimensionName1);	//维度名称
				fundDimension.setDimensionLimitType("1");	//维度类型
				fundDimension.setUserId(112233);	
				fundDimension.setUserLoginId("自动化测试");
							
			funddimensioncreateCall.setData(funddimensioncreateBean);
			funddimensioncreateCall.callService();	
			
			//获取返回报文的数据
			String dataStr = funddimensioncreateCall.getReturnData();
			//返回报文断言
			Logger.verifyNotNull(dataStr, "返回报文非空");			
			String Success =  new JSONObject(dataStr).getString("Success");
			Logger.verifyIsContains(Success, true, "\"Success\":true");
			String errMsg =  new JSONObject(dataStr).getString("ErrMsg");
			Logger.verifyIsNull(errMsg, "Msg等于空");
			
			if(errMsg == "null"){
			
			//获取返回报文的ProductID值
			String dimensionId =  new JSONObject(dataStr).getString("DimensionId");
			Logger.verifyNotNull(dimensionId, "断言ProductID非空");	
			
			//SQL Ymt_FundDimension ymtfp库
			YmtFundDimensionWapper ymtFundDimensionWapper = new YmtFundDimensionWapper();			
			List<YmtFundDimension>  fundDimensionlist = ymtFundDimensionWapper.selectdimension(strategyDimensionName1);
			YmtFundDimension ymtFundDimension = fundDimensionlist.get(0);
			//断言
			String did1 =ymtFundDimension.getDimensionId();
			Logger.verifyEquals(dimensionId, did1, "维度id");
			String sdname1=ymtFundDimension.getStrategyDimensionName();
			Logger.verifyEquals(strategyDimensionName1, sdname1, "维度名称");
			int dlt1=ymtFundDimension.getDimensionLimitType();
			Logger.verifyEquals(funddimensioncreateBean.getFundDimension().getDimensionLimitType(), Integer.toString(dlt1), "维度类型");
			int ds1=ymtFundDimension.getDimensionStatus();
			Logger.verifyEquals(1, ds1, "维度状态");
			int userid=ymtFundDimension.getUserId();
			Logger.verifyEquals(funddimensioncreateBean.getFundDimension().getUserId(), userid, "维护人id");
			String userLoginId=ymtFundDimension.getUserLoginId();
			Logger.verifyEquals(funddimensioncreateBean.getFundDimension().getUserLoginId(), userLoginId, "维护人名称");
			
			} else {			
                throw new Exception(errMsg);
            }
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_FundDimensionCreate_002() {
		Logger.start(false,"维度类型DimensionLimitType不能为空");
		try {
			//TODO 补全case代码
			//资金维度 （接口第一层）
			int num2 = (int)(Math.random()*100000);			
			funddimensioncreateBean.setFundDimension(fundDimension);
				//接口第二层
				fundDimension.setDimensionLimitType(null);
				fundDimension.setStrategyDimensionName("商品类目" + num2);	//维度名称
				fundDimension.setUserId(112233);	
				fundDimension.setUserLoginId("自动化测试");
			
			funddimensioncreateCall.setData(funddimensioncreateBean);
			funddimensioncreateCall.callService();		
			
//			//获取返回报文的数据
//			String dataStr = funddimensioncreateCall.getReturnData();
//			//返回报文断言			
//			String dimensionId =  new JSONObject(dataStr).getString("DimensionId");
//			Logger.verifyIsNull(dimensionId, "DimensionId为空");
//			String errCode =  new JSONObject(dataStr).getString("ErrCode");
//			Logger.verifyIsContains("1040", errCode, "ErrCode");
//			String errMsg =  new JSONObject(dataStr).getString("ErrMsg");
//			Logger.verifyIsContains("不能为空", errMsg, "维度类型DimensionLimitType不能为空");
//			String body =  new JSONObject(dataStr).getString("Body");
//			Logger.verifyIsNull(body, "Body为空");
//			String requestUrl =  new JSONObject(dataStr).getString("RequestUrl");
//			Logger.verifyIsNull(requestUrl, "RequestUrl为空");
//			String Success =  new JSONObject(dataStr).getString("Success");
//			Logger.verifyIsContains(false, Success, "\"Success\":false");
			
			fundDgetreturnerrcode("1040" , "资金维度值类型不能为空");
			
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_FundDimensionCreate_003() {
		Logger.start(false,"用户id不能为空");
		try {
			//TODO 补全case代码
			int num3 = (int)(Math.random()*100000);			
			funddimensioncreateBean.setFundDimension(fundDimension);
				//接口第二层
			fundDimension.setStrategyDimensionName("商品类目" + num3);	//维度名称
				fundDimension.setDimensionLimitType("1");	//维度类型
				fundDimension.setUserLoginId("自动化测试");
			
			funddimensioncreateCall.setData(funddimensioncreateBean);
			funddimensioncreateCall.callService();		
			
			//返回报文断言
			fundDgetreturnerrcode("1006" , "用户id不能为空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_FundDimensionCreate_004() {
		Logger.start(false,"用户名不能为空");
		try {
			//TODO 补全case代码
			int num4 = (int)(Math.random()*100000);			
			funddimensioncreateBean.setFundDimension(fundDimension);
				//接口第二层
				fundDimension.setStrategyDimensionName("商品类目" + num4);	//维度名称
				fundDimension.setDimensionLimitType("1");	//维度类型
				fundDimension.setUserId(112233);	
			
			funddimensioncreateCall.setData(funddimensioncreateBean);
			funddimensioncreateCall.callService();		
			
			//返回报文断言
			fundDgetreturnerrcode("1008" , "用户名不能为空");
					
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_FundDimensionCreate_005() {
		Logger.start(false,"资金维度名称不能为空");
		try {
			//TODO 补全case代码		
			funddimensioncreateBean.setFundDimension(fundDimension);
				//接口第二层
				
				fundDimension.setDimensionLimitType("1");	//维度类型
				fundDimension.setUserId(112233);
				fundDimension.setUserLoginId("自动化测试");	
			
			funddimensioncreateCall.setData(funddimensioncreateBean);
			funddimensioncreateCall.callService();		
			
			//返回报文断言
			fundDgetreturnerrcode("1022" , "资金维度名称不能为空");
					
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_FundDimensionCreate_006() {
		Logger.start(false,"资金维度名称不能重复");
		try {
			//TODO 补全case代码		
			funddimensioncreateBean.setFundDimension(fundDimension);
				//接口第二层
				fundDimension.setStrategyDimensionName("商品类目");	//维度名称
				fundDimension.setDimensionLimitType("1");	//维度类型
				fundDimension.setUserId(112233);
				fundDimension.setUserLoginId("自动化测试");	
			
			funddimensioncreateCall.setData(funddimensioncreateBean);
			funddimensioncreateCall.callService();		
			
			//返回报文断言
			fundDgetreturnerrcode("1032" , "资金维度名称不能重复");
					
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_FundDimensionCreate_007() {
		Logger.start(true,"创建资金维度信息(区间类型)");
		try {
			//TODO 补全case代码
			int num1 = (int)(Math.random()*100000);
			String strategyDimensionName1="商品类目" + num1;
			
			//资金维度 
			funddimensioncreateBean.setFundDimension(fundDimension);

			fundDimension.setStrategyDimensionName(strategyDimensionName1);	//维度名称
			fundDimension.setDimensionLimitType("2");	//维度类型 1单值类型 2区间类型
			fundDimension.setUserId(112233);	
			fundDimension.setUserLoginId("自动化测试");
							
			funddimensioncreateCall.setData(funddimensioncreateBean);
			funddimensioncreateCall.callService();	
			
			//获取返回报文的数据
			String dataStr = funddimensioncreateCall.getReturnData();
			//返回报文断言
			Logger.verifyNotNull(dataStr, "返回报文非空");			
			String Success =  new JSONObject(dataStr).getString("Success");
			Logger.verifyIsContains(Success, true, "\"Success\":true");
			String errMsg =  new JSONObject(dataStr).getString("ErrMsg");
			Logger.verifyIsNull(errMsg, "Msg等于空");
			
			if(errMsg == "null"){
			
			//获取返回报文的ProductID值
			String dimensionId =  new JSONObject(dataStr).getString("DimensionId");
			Logger.verifyNotNull(dimensionId, "断言ProductID非空");	
			
			//SQL Ymt_FundDimension ymtfp库
			YmtFundDimensionWapper ymtFundDimensionWapper = new YmtFundDimensionWapper();			
			List<YmtFundDimension>  fundDimensionlist = ymtFundDimensionWapper.selectdimension(strategyDimensionName1);
			YmtFundDimension ymtFundDimension = fundDimensionlist.get(0);
			//断言
			String did1 =ymtFundDimension.getDimensionId();
			Logger.verifyEquals(dimensionId, did1, "维度id");
			String sdname1=ymtFundDimension.getStrategyDimensionName();
			Logger.verifyEquals(strategyDimensionName1, sdname1, "维度名称");
			int dlt1=ymtFundDimension.getDimensionLimitType();
			Logger.verifyEquals(funddimensioncreateBean.getFundDimension().getDimensionLimitType(), Integer.toString(dlt1), "维度类型");
			int ds1=ymtFundDimension.getDimensionStatus();
			Logger.verifyEquals(1, ds1, "维度状态");
			int userid=ymtFundDimension.getUserId();
			Logger.verifyEquals(funddimensioncreateBean.getFundDimension().getUserId(), userid, "维护人id");
			String userLoginId=ymtFundDimension.getUserLoginId();
			Logger.verifyEquals(funddimensioncreateBean.getFundDimension().getUserLoginId(), userLoginId, "维护人名称");
			
			} else {			
                throw new Exception(errMsg);
            }
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	
	
}